package com.ksc.storekeeper.client.view.validation;

import com.github.gwtbootstrap.client.ui.base.TextBox;
import com.ksc.storekeeper.client.resources.StoreKeeperResources;

public class ValidatingTextBox extends TextBox implements IsValidatingWidget<String> {
	private final ValidatingHelper<String> helper;

	public ValidatingTextBox() {
		helper = new ValidatingHelper<String>(this);
	}

	public void setRequired(boolean required) {
		helper.setRequired(required);
	}

	@Override
	public Validation validate() {
		return helper.validate();
	}

	@Override
	public String getErrorMessage() {
		return helper.getErrorMessage();
	}

	@Override
	public void showInvalid() {
		helper.showInvalid();
	}

	@Override
	public void removeInvalid() {
		helper.removeInvalid();
	}

	@Override
	public void setMinLength(int length) {
		helper.setMinLength(length);
	}

	@Override
	public void setMaxLength(int length) {
		super.setMaxLength(length);
		helper.setMaxLength(length);
	}

	public void setNumeric(boolean numeric) {
		helper.setNumeric(numeric);
	}

	public void setAlpha(boolean alpha) {
		helper.setAlpha(alpha);
	}

	public void setAlphaNumeric(boolean an) {
		helper.setAlphaNumeric(an);
	}

	@Override
	public Validation validateDouble(String value) {
		return null;
	}

	@Override
	public Validation validateListBox(String value) {
		return null;
	}

	@Override
	public Validation validateEmail() {
		return helper.validateEmail();
	}

	@Override
	public Validation validatePassword() {
		return helper.validatePassword();
	}

	@Override
	public Validation validate(String date) {
		return null;
	}

	@Override
	public String getText() {
		return super.getText().trim();
	}

	@Override
	public void setEnabled(boolean enabled) {
		super.setEnabled(enabled);
		setStyleName(StoreKeeperResources.INSTANCE.storeKeeperCss().disabledTextField());
	}

	@Override
	public Validation validateDoubleWithMinLimit(Double value, Double minValue) {
		return null;
	}

	public void setPlaceholder(String text) {
		super.getElement().setAttribute("placeholder", text);
	}

	@Override
	public Validation validatePin() {
		return null;
	}

	public void setRegex(String regex) {
		helper.setRegex(regex);
	}

	public void setSpecificErrorMessage(String specificErrorMessage) {
		helper.setSpecificErrorMessage(specificErrorMessage);
	}

	public Validation validateOnBlur() {
		return helper.validateOnBlur();
	}
}